package fhv.at.imageprocessing.editors;

import javax.media.jai.KernelJAI;

/**
 * Erode kernel editor
 * 
 * @author phru
 * 
 */
public class ErodeKernelEditor extends KernelEditor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ErodeKernelEditor() {
		super();
		init();
	}

	private void init() {
		addPreDefinedItem("5x5 Square");
		addPreDefinedItem("5x5 Circle");
	}

	@Override
	protected void setPreDefinedKernel(String kernelName) {

		if (kernelName.equals("5x5 Square")) {
			setKernel5x5Square();
		} else if (kernelName.equals("5x5 Circle")) {
			setKernel5x5Circle();
		} else {
			setKernelDefault();
		}
		pcs.firePropertyChange("", null, null);
	}

	private void setKernel5x5Square() {
		float[] kernelData = { 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F,
				1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F,
				1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, };
		kernel = new KernelJAI(5, 5, kernelData);
		setValue(kernel);
	}

	private void setKernel5x5Circle() {
		float[] kernelData = { 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 1.0F,
				1.0F, 0.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.0F, 1.0F, 1.0F,
				1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, };
		kernel = new KernelJAI(5, 5, kernelData);
		setValue(kernel);
	}

}
